<template>
	<view>
		<view class="box" v-if="okShou == 0">
			<view class="img_box"><img style="width: 100%;height: 100%;" src="@/static/images/shoukuan.png" alt="" />
			</view>
			<view class="text_box">确认收款中...</view>
		</view>
		<view class="box" v-else-if="okShou == 1">
			<view class="img_box"><img style="width: 100%;height: 100%;" src="@/static/images/ok.png" alt="" />
			</view>
			<view class="text_box"></view>
		</view>
		<view class="box" v-else-if="okShou == 2">
			<view class="img_box"><img style="width: 100%;height: 100%;" src="@/static/images/quxiao.png" alt="" />
			</view>
			<view class="text_box">收款已取消</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				packageData: '',
				okShou: 0,
			}
		},
		onLoad(options) {
			this.packageData = options.data
			this.getPayment(this.packageData)
		},
		methods: {
			test() {
				this.okShou = 0
			},
			//拉起转账确认页面
			getPayment(packageData) {
				if (wx.canIUse('requestMerchantTransfer')) {
					wx.requestMerchantTransfer({
						mchId: '1712596890',
						appId: wx.getAccountInfoSync().miniProgram.appId,
						package: packageData,
						success: (res) => {
							// res.err_msg将在页面展示成功后返回应用时返回ok，并不代表付款成功
							if (res.err_msg && res.err_msg.indexOf('ok') > -1) {
								this.okShou = 1
							} else if (res.err_msg && res.err_msg.indexOf('cancel') > -1) {
								this.okShou = 2
							}
						},
						fail: (res) => {
							console.log('fail:', res);
						},
					});
				} else {
					wx.showModal({
						content: '你的微信版本过低，请更新至最新版本。',
						showCancel: false,
					});
				}
			},
		},
	}
</script>

<style scoped lang="scss">
	.box {
		width: 100vw;
		height: 100vh;
	}

	.img_box {
		width: 150rpx;
		height: 150rpx;
		position: absolute;
		left: 50%;
		top: 20%;
		transform: translate(-50%, -50%);
	}

	.text_box {
		width: 100%;
		height: 5vh;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 40rpx;
		position: absolute;
		left: 50%;
		top: 30%;
		transform: translate(-50%, -50%);
	}
</style>